<template>
  <div class="authContainer">
    <div class="timeCont" v-if="showCont && !showTimeOut">
      <div class="bannerCont">
        <img class="bannerImg" src="/img/banner/3.png" />
      </div>
      <div class="formCont">
        <div class="formTitle">申请企业认证</div>
        <logoUp @ok="getImg" :propsImg="bindInfo.enterprise_logo"></logoUp>
        <div class="compLogo">企业logo</div>
        <div class="formInput">
          <div class="inputName">
            <div class="mustIcon">*</div>
            <div class="inputNameText">企业全称</div>
          </div>
          <input
            v-model="bindInfo.enterprise_name"
            type="text"
            maxlength="18"
            placeholder="请输入企业全称"
          />
        </div>
        <div class="formInput">
          <div class="inputName">
            <div class="mustIcon">*</div>
            <div class="inputNameText">企业代码</div>
          </div>
          <input
            v-model="bindInfo.enterprise_code"
            type="text"
            maxlength="18"
            placeholder="请输入统一社会信用代码"
          />
        </div>
        <div class="formInput">
          <div class="inputName">
            <div class="inputName">
              <div class="mustIcon">*</div>
              <div class="inputNameText">企业规模</div>
            </div>
          </div>
          <div class="inputOut">
            <div class="inputMask" @click="enterprise_scaleShow = true"></div>
            <input
              v-model="bindInfo.enterprise_scale"
              placeholder="选择企业规模"
            />
          </div>
          <div
            @click="enterprise_scaleShow = true"
            class="iconfont icon-xiala"
          ></div>
        </div>
        <div class="formInput">
          <div class="inputName">
            <div class="inputName">
              <div class="mustIcon">*</div>
              <div class="inputNameText">所在城市</div>
            </div>
          </div>
          <div class="inputOut">
            <div class="inputMask" @click="enterprise_cityShow = true"></div>
            <input
              v-model="bindInfo.enterprise_city"
              placeholder="选择企业所在城市"
            />
          </div>
          <div
            @click="enterprise_cityShow = true"
            class="iconfont icon-xiala"
          ></div>
        </div>
        <div class="formInput">
          <div class="inputName">
            <div class="mustIcon">*</div>
            <div class="inputNameText">联系电话</div>
          </div>
          <input
            v-model="bindInfo.enterprise_phone"
            type="tel"
            maxlength="11"
            placeholder="请输入企业联系电话"
          />
        </div>
        <div class="formInput">
          <div class="inputName">
            <div class="inputNameText">企业邮箱</div>
          </div>
          <input
            v-model="bindInfo.enterprise_email"
            type="text"
            maxlength="18"
            placeholder="请输入企业邮箱"
          />
        </div>
        <div class="saveBtn" @click="subFn">
          {{ status == 1 ? "立即认证(免费)" : "修改企业信息" }}
        </div>
      </div>
    </div>
    <subLoad v-if="showSub"></subLoad>
    <van-popup
      :close-on-click-overlay="false"
      v-model:show="enterprise_scaleShow"
      round
      position="bottom"
    >
      <div class="maskCont">
        <div class="maskHead">选择企业规模</div>
        <van-picker
          @change="enterprise_scaleChange"
          :show-toolbar="false"
          title="标题"
          :columns="enterprise_scaleArr"
        />
        <div class="maskBtn" @click="enterprise_scaleSureFn">确认选择</div>
      </div>
    </van-popup>
    <van-popup
      :close-on-click-overlay="false"
      v-model:show="enterprise_cityShow"
      round
      position="bottom"
    >
      <div class="maskCont">
        <div class="maskHead">请选择你所在的城市</div>
        <van-area
          :columns-num="2"
          @change="enterprise_cityChange"
          confirm-button-text=""
          cancel-button-text=""
          :area-list="areaList"
        />
        <div class="maskBtn" @click="enterprise_citySureFn">确认选择</div>
      </div>
    </van-popup>
  </div>
</template>
<script>
import { showSuccessToast, showToast, showConfirmDialog } from "vant";
import logoUp from "@/components/public/logoUp.vue";
import subLoad from "@/components/public/subLoad.vue";
import { applyEnterprise, enterpriseShow } from "@/http/api";
import { areaList } from "@vant/area-data";

export default {
  components: { logoUp, subLoad },
  name: "",
  data() {
    return {
      showTimeOut: false,
      showCont: false,
      enterprise_scaleShow: false,
      showSub: false,
      enterprise_cityShow: false,
      status: this.$route.query.status,
      areaList: areaList,
      bindInfo: {
        enterprise_logo: "",
        enterprise_phone: "",
        enterprise_name: "",
        enterprise_email: "",
        enterprise_code: "",
        enterprise_scale: "",
        enterprise_city: "",
      },
      enterprise_scaleArr: [
        { text: "0-20人", value: "0-20人" },
        { text: "20-99人", value: "20-99人" },
        { text: "100-499人", value: "100-499人" },
        { text: "500-999人", value: "500-999人" },
        { text: "1000-9999人", value: "1000-9999人" },
        { text: "10000人以上", value: "10000人以上" },
      ],
    };
  },
  props: {},
  setup() {},
  methods: {
    enterprise_citySureFn() {
      if (this.bindInfo.enterprise_city == "") {
        this.bindInfo.enterprise_city = "北京市";
      }
      this.enterprise_cityShow = false;
    },
    getImg(data) {
      this.bindInfo.enterprise_logo = data;
    },
    //选择城市
    enterprise_cityChange(selectedValues, selectedOptions) {
      if (selectedValues.selectedOptions.length > 0) {
        this.bindInfo.enterprise_city = selectedValues.selectedOptions[1].text;
      }
    },
    // 工作职位
    enterprise_scaleChange(
      selectedValues,
      selectedOptions,
      selectedIndexes,
      columnIndex
    ) {
      this.bindInfo.enterprise_scale = selectedValues.selectedValues.join("-");
    },
    enterprise_scaleSureFn() {
      if (this.bindInfo.enterprise_scale == "") {
        this.bindInfo.enterprise_scale = "0-20人";
      }
      this.enterprise_scaleShow = false;
    },
    subFn() {
      let data = this.bindInfo;
      if (!data.enterprise_logo) {
        showToast("请上传logo");
        return false;
      } else if (!data.enterprise_name) {
        showToast("请输入企业名称");
        return false;
      } else if (!data.enterprise_code) {
        showToast("请输入企业代码");
        return false;
      } else if (!data.enterprise_scale) {
        showToast("请选择企业规模");
        return false;
      } else if (!data.enterprise_phone) {
        showToast("请输入联系电话");
        return false;
      } else if (!data.enterprise_email) {
        showToast("请输入企业邮箱");
        return false;
      }
      showConfirmDialog({
        title: "申请提示",
        message: "请确认申请信息是否准确，避免影响审核进度。",
      })
        .then(() => {
          // on confirm
          this.showSub = true;
          applyEnterprise(data).then((res) => {
            if (res.data.code == 1) {
              showSuccessToast("申请成功");
            } else {
              showToast(res.data.msg);
            }
            this.showSub = false;
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    getData() {
      enterpriseShow()
        .then((res) => {
          if (res.data.code == 1) {
            this.bindInfo = res.data.data;
          } else {
            showToast(res.data.msg);
          }
          this.showCont = true;
        })
        .catch(() => {
          this.showTimeOut = true;
          this.showCont = true;
        });
    },
  },
  mounted() {},
  created() {
    if (this.status == 0) {
      this.showCont = true;
    } else {
      this.getData();
    }
  },
};
</script>
<style scoped lang="less">
.authContainer {
  background-color: #f1f4fb;
  padding-bottom: 0rem;
  box-sizing: border-box;
  min-height: 100vh;
  .bannerCont {
    width: 100%;
    color: #fff;
    display: flex;
    justify-content: space-between;
    box-sizing: border-box;
    .bannerImg {
      width: 100%;
    }
  }
  .formCont {
    background-color: #fff;
    width: 92%;
    margin: 0 auto;
    position: relative;
    top: -1rem;
    padding: 1rem 4%;
    border-radius: 0.75rem;
    box-sizing: border-box;
    .formTitle {
      font-size: 0.8rem;
      font-weight: bold;
      margin-bottom: 1rem;
      .iconfont {
        color: #86a9fb;
        font-size: 1rem;
        margin-right: 0.25rem;
        position: relative;
        top: 0.05rem;
      }
    }
    .compHead {
      width: 4rem;
      margin: 0.75rem auto 0;
      height: 4rem;
      background-color: #fff;
      // padding: 0.15rem;
      box-sizing: border-box;
      border: 0.2rem solid #86a9fb;
      border-radius: 50%;
      box-sizing: border-box;
      font-size: 0;
      position: relative;
      .upImgIcon {
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.1);
        border-radius: 50%;
        position: absolute;
        left: 0;
        top: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        .iconfont {
          font-size: 1.2rem;
          color: #666;
        }
      }
      img {
        width: 100%;
        border-radius: 50%;
      }
    }
    .compLogo {
      text-align: center;
      // font-size: 0.6rem;
      margin: 0.5rem 0 1.25rem;
    }
    .inputName {
      width: 4rem;
      position: relative;
      .mustIcon {
        font-size: 0.7rem;
        top: 0rem;
        left: -0.4rem;
        position: absolute;
        color: #ff5757;
      }
    }
    .icon-xiala {
      width: 1.5rem;
      font-size: 0.8rem;
      color: #ccc;
      text-align: center;
    }
    .inputOut {
      flex: 1;
      width: 3rem;
      position: relative;
      .inputMask {
        width: 100%;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
      }
      input {
        width: 90%;
        border: none;
        background: none;
        outline: none;
      }
    }
    input {
      flex: 1;
      width: 3rem;
      border: none;
      background: none;
      outline: none;
    }
    .formInput {
      display: flex;
      padding: 0.75rem 1rem;
      box-sizing: border-box;
      align-items: center;
      width: 100%;
      background-color: #f6f7f9;
      margin-bottom: 1rem;
      border-radius: 1.5rem;
      .inputName {
        width: 3.2rem;
      }
    }
    .saveBtn {
      width: 100%;
      padding: 0.75rem 0;
      text-align: center;
      background-image: linear-gradient(to right, #cbd8f7, #86a9fb);
      color: #fff;
      border-radius: 2rem;
    }
  }
  .maskCont {
    padding: 1.5rem 4%;
    box-sizing: border-box;
    .maskHead {
      width: 100%;
      text-align: center;
      font-size: 1rem;
      font-weight: bold;
      margin-bottom: 1.5rem;
      .maskHeadTip {
        font-size: 0.6rem;
        font-weight: normal;
        color: #999;
        text-align: center;
      }
      .redTip {
        color: #ff5757;
      }
    }
    .maskBtn {
      width: 100%;
      text-align: center;
      padding: 0.6rem 0;
      background-color: #86a9fb;
      border: 1px solid #86a9fb;
      color: #fff;
      border-radius: 2rem;
      margin-top: 1.5rem;
    }
  }
}
</style>
